home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
BUSINESS
/
STATA3.LZH
/
YOURDATA.TUT
< prev
Wrap
Text File
|
1988-08-29
|
14KB
|
405 lines
set output error
set display page 23
set more 1
#delimit ;
di _n(5) in wh
" ___ ____ ____ ____ ____ tm" _n
" /__ / ____/ / ____/" _n
"___/ / /___/ / /___/ Entering your data into Stata" _n
"-------------------------------------------------------------"
_n(2) ;
di in gr
"In this tutorial we show you how to enter your data into Stata. The commands"
_n
"we discuss are:" _n(2)
_col(21) in wh "input infile" in gr _n(2)
"Before entering data into Stata, clear any data you already have loaded by"
_n
"typing '"
in wh "drop _all" in gr "' and '" in wh "label drop _all" in gr
"'. The '" in wh "drop _all" in gr "' command tells Stata" _n
"to eliminate any data stored in memory. The '"
in wh "label drop _all" in gr "' command tells"
_n
"Stata to eliminate any value labels stored in memory, too. You can learn" _n
"about value labels by typing '" in wh "help label" in gr
"' at the conclusion of this tutorial." _n(5) in wh
". drop _all" _n(2)
". label drop _all" ;
#delimit cr
mac def path
capture run nullfile.tut
if _rc {
mac def path "\stata\"
capture run %path`nullfile.tut
if _rc {
mac def path "/usr/stata/"
capture run %path`nullfile.tut
if _rc {
#delimit ;
di in red
"I cannot find the other tutorial files. I have looked in the current" _n
"directory and in \stata (DOS) or /usr/stata (Unix). Is Stata installed" _n
"correctly?" _n(2)
"In any case, I cannot run the tutorial." ;
#delimit cr
exit
}
}
}
macro define F5 "do %path`contents.tut;"
macro define F6 "do %path`yourdata.tut;"
#delimit ;
drop _all ;
label drop _all ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"The simplest way to enter small data sets into Stata is the '"
in wh "input" in gr "' command." _n
"This command tells Stata that data will be entered from the keyboard. The"
_n
"syntax is" _n(2)
_col(25) in wh "input " in gr "varlist" _n(2)
"where varlist is a list of the variables you wish to enter. You will be" _n
"prompted to enter each observation one at a time. When you have entered all"
_n
"the observations, you type '" in wh "end" in gr "' in lowercase letters." _n(2)
"We will input a small data set containing automobile information. Let's enter"
_n
"our first car's id code, mileage, weight, and price:" _n
in wh _dup(79) "-" _n(3)
". input id mpg weight price" _n(2)
in gr _col(13) "id mpg weight price" _n
in bl " 1" in wh ". 1 22 2930 4099" _n
in bl " 2" in wh ". end" _n;
input id mpg weight price;
1 22 2930 4099;
end;
di ; set more 0 ; more ; set more 1 ;
di in wh _dup(79) "-" _n in gr
"If the above appears rather confusing, it is only because it happened so" _n
"quickly." _n(2)
_col(8) "We typed '" in wh "input id mpg weight price" in gr "'." _n(2)
_col(8) "Stata responded by typing a header and then prompting us for the"
_n
_col(8) "first observation." _n(2)
_col(8) "We typed '" in wh "1 22 2930 4099" in gr "' and pressed Return." _n(2)
_col(8) "Stata responded by prompting us for the second observation." _n(2)
_col(8) "We typed '" in wh "end" in gr "' and pressed Return." _n
in wh _dup(79) "-" _n ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Once we have some data in memory, we can type '"
in wh "input" in gr "' without arguments to add" _n
"more observations:" _n
in wh _dup(79) "-" _n(3)
". input" _n(2)
in gr _col(13) "id mpg weight price" _n
in bl " 2" in wh ". 2 17 3350 4749" _n
in bl " 3" in wh ". 3 22 2640 3799" _n
in bl " 4" in wh ". 4 20 3250 4816" _n
in bl " 5" in wh ". 5 15 4080 7827" _n
in bl " 6" in wh ". end" _n;
input ;
2 17 3350 4749 ;
3 22 2640 3799 ;
4 20 3250 4816 ;
5 15 4080 7827 ;
end ;
di _n in wh _dup(79) "-" _n in gr
"We added four more observations to our data. Let's '"
in wh "describe" in gr "' and '" in wh "list" in gr "'" _n
"our data just to prove to ourselves that everything worked:" _n
in wh _dup(79) "-" _n(2)
". describe" ;
set more 0 ; more ; set more 1 ;
noisily describe ;
di _n(2) in wh ". list" ;
noisily list ;
di _n ; set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"You now know how to enter numeric data into Stata." _n(2)
"If our data had contained character variables, however, we would have to do"
_n
"things slightly differently. Stata has five storage types:" _n(2)
_col(8) in wh "int" _col(16) in gr "integers between -32,768 and 32,766" _n
_col(8) in wh "long" _col(16) in gr
"integers between -2,147,483,648 and 2,147,583,646" _n
_col(8) in wh "float" _col(16) in gr
"floating-point numbers between +/-10^-37 and +/-10^37" _n
_col(8) in wh "double" _col(16) in gr
"floating-point numbers between +/-10^-99 and +/-10^99" _n(2)
_col(8) in wh "str" in gr "#" _col(16) "strings of maximum length #" _n ;
di in gr
"When you don't tell Stata what type of variable you are creating, Stata as-" _n
"sumes it is a " in wh "float" in gr "." _n(2)
in wh "str" in gr
"# is not really a storage type, you must substitute a number between "
in wh "2" in gr " and"
_n
in wh "80" in gr
" for the # symbol, producing, for instance, "
in wh "str2" in gr " or " in wh "str10" in gr " or " in wh "str80" in gr "
. The" _n
"number specifies the maximum width of the string." _n(2)
"Anytime you create a variable, you can specify its storage type by typing the"
_n
"storage type in front of the variable's name." _n
in wh _dup(79) "-" _n ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Let's try out our newfound knowledge by reentering our automobile data:" _n
in wh _dup(79) "-" _n(2)
". drop _all" _n(2)
". input str14 make mpg weight price" _n(2)
in gr _col(13) "make mpg weight price" _n
in bl " 1" in wh ". " _quote "AMC Concord" _quote " 22 2930 4099" _n
in bl " 2" in wh ". " _quote "AMC Pacer" _quote " 17 3350 4749" _n
in bl " 3" in wh ". " _quote "AMC Spirit" _quote " 22 2640 3799" _n
in bl " 4" in wh ". " _quote "Buick Century" _quote " 20 3250 4816" _n
in bl " 5" in wh ". " _quote "Buick Electra" _quote " 15 4080 7827" _n
in bl " 6" in wh ". end" _n;
drop _all;
input str14 make mpg weight price ;
"AMC Concord" 22 2930 4099;
"AMC Pacer" 17 3350 4749;
"AMC Spirit" 22 2640 3799;
"Buick Century" 20 3250 4816;
"Buick Electra" 15 4080 7827;
end;
di in wh _dup(79) "-" _n in gr
"The " in wh "str14" in gr
" typed in front of make affected only the make variable, all the re-" _n
"maining variables are " in wh "float" in gr
". If we had typed '" in wh "input str14 make int mpg weight" _n
"price" in gr
"', then mpg would have been an " in wh "int" in gr
", but weight and price would still have" _n
"been " in wh "float" in gr
"s. Note that we typed double quotes around the strings themselves." _n
in wh _dup(79) "-" _n ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"To prove everything worked, let's " in wh "describe" in gr " and "
in wh "list" in gr " the data:" _n
in wh _dup(79) "-" _n(2)
". describe" ;
noisily describe ;
di _n in wh ". list" ;
noisily list ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"For larger data sets, typing data from the keyboard is tedious. Stata can "
"read" _n
"ASCII data files directly from disk with the '" in wh "infile" in gr
"' command. ASCII data sets" _n
"can be created in your favorite editor or they can be output from another"
" soft-" _n
"ware package." _n(2)
"We have previously created a file called "
in ye "autodata.raw" in gr " using our favorite ed-" _n
"itor. We'll show you the contents of the file:" _n
in wh _dup(79) "-" _n(2)
". type %path`autodata.raw" ;
noisily type %path`autodata.raw ;
di _n in wh _dup(79) "-" _n in gr
"This is the same data we typed in from the keyboard." _n
in wh _dup(79) "-" _n ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"To input this data from the keyboard, we typed:" _n(2)
_col(8) in wh "input str14 make mpg weight price" _n(2)
in gr "To input it from the file %path`autodata.raw, we type:" _n(2)
_col(8) in wh "infile str14 make mpg weight price using %path`autodata" _n(2)
in wh _dup(79) "-" _n(3)
". drop _all" _n(2)
". infile str14 make mpg weight price using %path`autodata" ;
drop _all ;
noisily infile str14 make mpg weight price using %path`autodata ;
di _n(2) in wh _dup(79) "-" _n in gr
"Stata read the data from disk. Once again, let's " in wh "describe"
in gr " and " in wh "list" in gr " the data:" _n
in wh _dup(79) "-" _n(2)
". describe" ;
set more 0 ; more ; set more 1 ;
noisily describe ;
di _n in wh ". list" ;
noisily list ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"A more advanced method of entering data from disk is to use data dictionaries."
_n
"A dictionary tells Stata the variable names, any formatting information, and"
_n
"labeling. Dictionaries are useful because they leave behind a permanent rec-"
_n
"ord of the ASCII file's contents." _n(2)
"Dictionaries have too many capabilities to be completely explained here, but"
_n
"you can learn more by typing '"
in wh "help infile" in gr "' at the conclusion of this tutorial." _n
"We will, however, show you two examples. We have two more files to read, one"
_n
"much like you might create using your word processor or editor, and the second"
_n
"much like a mainframe computer might manufacture." _n ;
di in gr
"The files are called "
in ye "autodata.dct" in gr " and " in ye "mainfram.dct" in gr
". Both contain data on the" _n
"same five cars we've used throughout this tutorial." _n
in wh _dup(79) "-" _n(5)
". drop _all" _n(2)
". type %path`autodata.dct" ;
set more 0 ; more ; set more 1 ;
drop _all ;
noisily type %path`autodata.dct ;
di _n(2) in wh _dup(79) "-" _n in gr
"This is a simple dictionary. To read the data, we type:" _n
in wh _dup(79) "-" _n(2)
". infile using %path`autodata.dct" ;
set more 0 ; more ; set more 1 ;
noisily infile using %path`autodata.dct ;
di _n(2) in wh _dup(79) "-" _n in gr
"The data has been read. We won't bother to prove it, but notice that Stata"
_n
"types the dictionary so that you know what it just read." _n
in wh _dup(79) "-" _n(2)
". drop _all" ;
drop _all ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh _dup(79) "-" _n in gr
"Our last example is more complicated. The dictionary not only identifies the"
_n
"variables, but it tells Stata how to read them. The data are run together"
_n
"much like a mainframe computer would do." _n
in wh _dup(79) "-" _n(2)
". type %path`mainfram.dct" ;
noisily type %path`mainfram.dct ;
di in wh _dup(79) "-" _n in gr
"To read the data, we type:" _n
in wh _dup(79) "-" _n(2)
". infile using %path`mainfram.dct" ;
set more 0 ; more ; set more 1 ;
noisily infile using %path`mainfram.dct ;
di _n(4) in wh _dup(79) "-" _n in gr
"The data has now been read. This time we will prove it:" _n
in wh _dup(79) "-" _n(3)
". describe" ;
set more 0 ; more ; set more 1 ;
noisily describe ;
di _n in wh ". list" ;
noisily list ;
set more 0 ; more ; set more 1 ;
di _n(2) in wh
"Saving data" _n
"-----------" _n ;
di in gr
"After you have entered data into Stata, you can save it. The command is:"
_n(2)
_col(16) in wh "save" in gr " filename" _n(2)
"If you do not specify the extension for the filename, Stata assumes the ex-"
_n
"tension '" in ye ".dta" in gr
"'. For instance, we could type '" in wh "save auto" in gr
"' to save this data." _n
"It would be saved in the file " in ye "auto.dta" in gr
". The command to retrieve previously" _n
"saved data is:" _n(2)
_col(16) in wh "use" in gr " filename [" in wh ", clear" in gr "]" _n(2)
"Thus, the next time we want to use "
in ye "auto.dta" in gr ", we could type '" in wh "use auto"
in gr "' or '" in wh "use" _n
"auto, clear" in gr "'. Sometimes '" in wh "use auto" in gr
"' will work, but '" in wh "use auto, clear" in gr "' will al-" _n
"ways work. Stata stores data in memory. The "
in wh "clear" in gr " option tells Stata that" _n
"it's okay to drop the data in memory in order to retrieve the new data."
_n ;
/*
set more 0 ; more ; set more 1 ;
di _n(4) in wh
"Saving data" _n
"-----------" _n ;
*/
di in gr
"Although we would like to show you the " in wh "save" in gr
" command, we are not going to." _n
"There are two reasons:" _n ;
set more 0 ; more ; set more 1 ;
di in gr
_col(9) "1. For those of you who have the full Stata system, we don't" _n
_col(13) "think it would be nice to write on your disk." _n(2)
_col(9) "2. For those of you who have only the demonstration system, the" _n
_col(13) in wh "save" in gr " command has been removed." ;
set more 0 ; more ; set more 1 ;
di _n(4) in wh
"Stat/Transfer" _n
"-------------" _n ;
di in gr
"There's one more way to get data into Stata, at least for DOS users, and it" _n
"is the most convenient if the data you need is in Lotus, Symphony, dBase, "
"Gauss" _n
"SPSS, or SYSTAT formats. It's called Stat/Transfer, an extra cost option" _n
"available from us." _n(2)
"We didn't write Stat/Transfer, but we do recommend it. It's menu driven and"
_n
"at the touch of a key it will convert data from one software format to "
"another." _n(12) ;
drop _all ;
label drop _all ;
drop _all ;
label drop _all ;
macro define F6 "do %path`intro.tut;";
set more 0 ; more ; set more 1 ;
di _n(4) in white
"Demonstration ends" _n
"------------------" _n ;
di in green
"That concludes our short demonstration, but there's much more. We now return"
_n
"control to you. Some suggestions:" _n ;
di in green
"If you ..." _col(34) "Then we will show you ..." _n
" Press " in white "F5" in green _col(38) "a table of tutorial contents" _n
" Press " in white "F6" in green _col(38) "the first tutorial, "
in white "intro.tut" _n ;
run %path`tobuy.tut ;